package master.ghrm.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Version;

@Entity
public class CategoryElaboration extends AbstractBaseEntity {
	private static final long serialVersionUID = 1L;

	public static final int LENGTH_TEXT = 1000;

	@Embeddable
	public static class Id implements Serializable {

		private static final long serialVersionUID = 1L;

		@ManyToOne
		@JoinColumn(name = "assessment_id")
		private Assessment assessment;

		@ManyToOne
		@JoinColumn(name = "category_id")
		private EvalCategory category;

		/**
		 * Public constructor.
		 * 
		 * @param anAssessment assessment this ID links to.
		 * @param aCategory evaluation category this ID links to.
		 */
		public Id(Assessment anAssessment, EvalCategory aCategory) {
			super();
			this.assessment = anAssessment;
			this.category = aCategory;
		}

		/**
		 * Default constructor for persistence.
		 */
		Id() {
			super();
		}

		/**
		 * @return the assessment
		 */
		public Assessment getAssessment() {
			return assessment;
		}

		/**
		 * @param anAssessment the assessment to set
		 */
		void setAssessment(Assessment anAssessment) {
			this.assessment = anAssessment;
		}

		/**
		 * @return the category
		 */
		public EvalCategory getCategory() {
			return category;
		}

		/**
		 * @param aCategory the category to set
		 */
		void setCategory(EvalCategory aCategory) {
			this.category = aCategory;
		}

		/**
		 * Eclipse generated.
		 * 
		 * @see java.lang.Object#hashCode()
		 */
		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + ((assessment == null) ? 0 : assessment.hashCode());
			result = prime * result + ((category == null) ? 0 : category.hashCode());
			return result;
		}

		/**
		 * Eclipse generated.
		 * 
		 * @see Object#equals(Object)
		 */
		@Override
		public boolean equals(Object obj) {
			if (this == obj) {
				return true;
			}
			if (obj == null) {
				return false;
			}
			if (getClass() != obj.getClass()) {
				return false;
			}
			final Id other = (Id) obj;
			if (assessment == null) {
				if (other.assessment != null) {
					return false;
				}
			} else if (!assessment.equals(other.assessment)) {
				return false;
			}
			if (category == null) {
				if (other.category != null) {
					return false;
				}
			} else if (!category.equals(other.category)) {
				return false;
			}
			return true;
		}
	}

	@EmbeddedId
	private Id id;

	@Column(length = LENGTH_TEXT, nullable = false)
	private String text;

	@Version
	private Long version;

	/**
	 * Default constructor, for persistence.
	 */
	CategoryElaboration() {
		super();
	}

	/**
	 * Minimal public constructor.
	 * 
	 * @param anId ID of this elaboration.
	 */
	public CategoryElaboration(Id anId) {
		super();
		this.id = anId;
	}

	/**
	 * Full constructor.
	 * 
	 * @param anId ID of the elaboration.
	 * @param aText text of the elaboration.
	 */
	public CategoryElaboration(Id anId, String aText) {
		super();
		this.id = anId;
		this.text = aText;
	}

	/**
	 * @return the ID
	 */
	public Id getId() {
		return id;
	}

	/**
	 * @param anId the ID to set
	 */
	public void setId(Id anId) {
		this.id = anId;
	}

	/**
	 * @return the text
	 */
	public String getText() {
		return text;
	}

	/**
	 * @param aText the text to set
	 */
	public void setText(String aText) {
		this.text = aText;
	}

	/**
	 * For persistence use, optimistic locking.
	 * 
	 * @return the version
	 */
	Long getVersion() {
		return version;
	}

	/**
	 * For persistence use, optimistic locking.
	 * 
	 * @param aVersion the version to set
	 */
	void setVersion(Long aVersion) {
		this.version = aVersion;
	}

	/**
	 * Return empty array.
	 * 
	 * @see com.levi9.hrm.model.base.AbstractBaseEntity#getExcludedAttributes()
	 */
	@Override
	protected String[] getExcludedAttributes() {
		return new String[] {};
	}
}
